package com.wayhome.srpingbootmybatis.controller.excel;

import com.alibaba.excel.EasyExcel;
import com.wayhome.srpingbootmybatis.dto.OpspRegDTO;
import com.wayhome.srpingbootmybatis.excel.Dr9225AccessInfo;
import com.wayhome.srpingbootmybatis.excel.PsnNoExcel;
import com.wayhome.srpingbootmybatis.excelListener.OpspRegListener;
import com.wayhome.srpingbootmybatis.mapper.OpspRegMapper;
import com.wayhome.srpingbootmybatis.service.OpspRegService;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/opt/opspReg")
public class OpspRegController {

    @Resource
    private OpspRegService opspRegService;

    @Resource
    private OpspRegMapper mapper;

    @PostMapping("/queryOpspRegDelInfo")
    public List<String> queryOpspRegDelInfo(MultipartFile file) {
        OpspRegListener opspRegListener = new OpspRegListener(mapper);
        try {
            InputStream inputStream = file.getInputStream();
            EasyExcel.read(inputStream, PsnNoExcel.class, opspRegListener).sheet().doRead();
            List<String> delList = opspRegListener.getDelList();
            return delList;
        }catch (Exception e) {
            log.error("查询慢性病信息失败", e);
        }
        return Collections.emptyList();
    }

    @GetMapping("/queryOpspRegDelInfoByPsnNo")
    public List<OpspRegDTO> queryOpspRegDelInfoByPsnNo(@RequestParam("psnNo") String psnNo) {
        OpspRegListener opspRegListener = new OpspRegListener(mapper);
        try {List<String> psnNoList = Arrays.asList(psnNo);
            List<OpspRegDTO> opspRegDTOS = mapper.queryOpspRegListByPsnNo(psnNoList);
            return opspRegDTOS;
        }catch (Exception e) {
            log.error("查询慢性病信息失败", e);
        }
        return Collections.emptyList();
    }
}
